﻿
namespace NetROS.Tiers.Windows.Forms
{
	/// <summary>
	/// abstract ArtiklKategorija typed datagridview
	/// </summary>
	[System.ComponentModel.DesignerCategoryAttribute("code")]
	public abstract class ArtiklKategorijaDataGridViewBase : System.Windows.Forms.UserControl
	{	
		/// <summary> 
		/// Thrown when the current Entity changed.
		/// </summary>
		public event System.EventHandler<ArtiklKategorijaDataGridViewEventArgs> CurrentEntityChanged;
		
		#region Fields
				
		/// <summary> 
		/// the current entity.
		/// </summary>
		private Entities.ArtiklKategorija _currentArtiklKategorija = null;
		//private Dictionary<string, string> _columnsHeaders = new Dictionary<string, string>();
		
		/// <summary> 
		/// the datagridview instance
		/// </summary>
		protected System.Windows.Forms.DataGridView uxArtiklKategorijaDataGridView;
		
		/// <summary> 
		/// the errorprovider
		/// </summary>
		protected System.Windows.Forms.ErrorProvider uxArtiklKategorijaErrorProvider;
		
		/// <summary> 
		/// the bindingsource
		/// </summary>
		protected System.Windows.Forms.BindingSource uxArtiklKategorijaBindingSource;
		
		
		/// <summary> 
		/// the DGV column associated with the ID property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxIDDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the Naziv property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxNazivDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the IDRoditelj property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxIDRoditeljDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the Hierarchy property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxHierarchyDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the Lvl property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxLvlDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the Abstraktna property
		/// </summary>
		protected System.Windows.Forms.DataGridViewCheckBoxColumn uxAbstraktnaDataGridViewColumn;
		
		#endregion
					
		#region Combo list
		
		#endregion
		
		#region Main Datasource
		
		private Entities.TList<Entities.ArtiklKategorija> _ArtiklKategorijaList;
				
		/// <summary> 
		/// The list of ArtiklKategorija to be displayed in the DGV.
		/// </summary>
		[System.ComponentModel.Category("Data")]
		public Entities.TList<Entities.ArtiklKategorija> ArtiklKategorijaList
		{
			get {return this._ArtiklKategorijaList;}
			set
			{
				this._ArtiklKategorijaList = value;
				this.uxArtiklKategorijaBindingSource.DataSource = null;
				this.uxArtiklKategorijaBindingSource.DataSource = value;
				this.uxArtiklKategorijaDataGridView.DataSource = null;
				this.uxArtiklKategorijaDataGridView.DataSource = this.uxArtiklKategorijaBindingSource;				
				//this.uxArtiklKategorijaBindingSource.ListChanged += new System.ComponentModel.ListChangedEventHandler(uxArtiklKategorijaBindingSource_ListChanged);
				this.uxArtiklKategorijaBindingSource.CurrentItemChanged += new System.EventHandler(OnArtiklKategorijaBindingSourceCurrentItemChanged);
			}
		}
		
		private void OnArtiklKategorijaBindingSourceCurrentItemChanged(object sender, System.EventArgs e)
		{
			_currentArtiklKategorija = uxArtiklKategorijaBindingSource.Current as Entities.ArtiklKategorija;
			
			if (_currentArtiklKategorija != null)
			{
				_currentArtiklKategorija.Validate();
			}
			//_ArtiklKategorija.Validate();
			OnCurrentEntityChanged();
		}

		//void uxArtiklKategorijaBindingSource_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
		//{
			//throw new Exception("The method or operation is not implemented.");
		//}		
		
		#endregion
		
		/// <summary>
		/// Gets the currently selected <c cref="Entities.ArtiklKategorija"/> instance.
		/// </summary>
		public Entities.ArtiklKategorija SelectedArtiklKategorija
		{
			get {return this._currentArtiklKategorija;}
		}
		
		#region other properties
		
		/// <summary>
		/// Gets or sets a value indicating whether you have provided your own data-management operations for the DataGridView control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool VirtualMode
		{
			get {return this.uxArtiklKategorijaDataGridView.VirtualMode;}
			set
			{
				this.uxArtiklKategorijaDataGridView.VirtualMode = value;
			}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the option to add rows is displayed to the user.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToAddRows
		{
			get {return this.uxArtiklKategorijaDataGridView.AllowUserToAddRows;}
			set {this.uxArtiklKategorijaDataGridView.AllowUserToAddRows = value;}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the user is allowed to delete rows from the DataGridView.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToDeleteRows
		{
			get {return this.uxArtiklKategorijaDataGridView.AllowUserToDeleteRows;}
			set {this.uxArtiklKategorijaDataGridView.AllowUserToDeleteRows = value;}
		}
		
		/// <summary>
		/// Gets the <c cref="DataGridView"/> instance.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public System.Windows.Forms.DataGridView DataGridView
		{
			get {return this.uxArtiklKategorijaDataGridView;}
		}
		
		/// <summary>
		/// Gets a collection that contains all the columns in the control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]		
		[System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Visible)]
		//[System.ComponentModel.EditorAttribute("System.Windows.Forms.Design.DataGridViewColumnCollectionEditor, System.Design", typeof(System.Drawing.Design.UITypeEditor))] 
		public System.Windows.Forms.DataGridViewColumnCollection Columns
		{
			get { return this.uxArtiklKategorijaDataGridView.Columns; }
		}
		
		#endregion
		
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;
	
		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}
	
		#region Constructor
	
		/// <summary>
		/// Initializes a new instance of the <see cref="ArtiklKategorijaDataGridViewBase"/> class.
		/// </summary>
		public ArtiklKategorijaDataGridViewBase()
		{			
			this.components = new System.ComponentModel.Container();			
			
			this.uxArtiklKategorijaDataGridView = new System.Windows.Forms.DataGridView();
			this.uxArtiklKategorijaBindingSource = new System.Windows.Forms.BindingSource(this.components);
			this.uxArtiklKategorijaErrorProvider = new System.Windows.Forms.ErrorProvider(this.components);
			this.uxIDDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxNazivDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxIDRoditeljDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxHierarchyDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxLvlDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxAbstraktnaDataGridViewColumn = new System.Windows.Forms.DataGridViewCheckBoxColumn();
			((System.ComponentModel.ISupportInitialize)(this.uxArtiklKategorijaDataGridView)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxArtiklKategorijaBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxArtiklKategorijaErrorProvider)).BeginInit();
			this.SuspendLayout();
						
			// 
			// uxArtiklKategorijaErrorProvider
			// 
			this.uxArtiklKategorijaErrorProvider.ContainerControl = this;
			this.uxArtiklKategorijaErrorProvider.DataSource = this.uxArtiklKategorijaBindingSource;						
			// 
			// uxArtiklKategorijaDataGridView
			// 
			this.uxArtiklKategorijaDataGridView.AutoGenerateColumns = false;
			this.uxArtiklKategorijaDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
			this.uxArtiklKategorijaDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
		this.uxIDDataGridViewColumn,
		this.uxNazivDataGridViewColumn,
		this.uxIDRoditeljDataGridViewColumn,
		this.uxHierarchyDataGridViewColumn,
		this.uxLvlDataGridViewColumn,
		this.uxAbstraktnaDataGridViewColumn			});
			this.uxArtiklKategorijaDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
			this.uxArtiklKategorijaDataGridView.Location = new System.Drawing.Point(0, 0);
			this.uxArtiklKategorijaDataGridView.Name = "uxArtiklKategorijaDataGridView";
			this.uxArtiklKategorijaDataGridView.Size = new System.Drawing.Size(470, 300);
			this.uxArtiklKategorijaDataGridView.TabIndex = 0;	
			this.uxArtiklKategorijaDataGridView.BackgroundColor = System.Drawing.Color.WhiteSmoke;
			this.uxArtiklKategorijaDataGridView.EnableHeadersVisualStyles = false;
			this.uxArtiklKategorijaDataGridView.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.OnArtiklKategorijaDataGridViewDataError);
			this.uxArtiklKategorijaDataGridView.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnArtiklKategorijaDataGridViewCellValueNeeded);
			this.uxArtiklKategorijaDataGridView.CellValuePushed += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnArtiklKategorijaDataGridViewCellValuePushed);
			
			//
			// uxIDDataGridViewColumn
			//
			this.uxIDDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIDDataGridViewColumn.DataPropertyName = "ID";
			this.uxIDDataGridViewColumn.HeaderText = "ID";
			this.uxIDDataGridViewColumn.Name = "uxIDDataGridViewColumn";
			this.uxIDDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIDDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIDDataGridViewColumn.ReadOnly = true;		
			//
			// uxNazivDataGridViewColumn
			//
			this.uxNazivDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxNazivDataGridViewColumn.DataPropertyName = "Naziv";
			this.uxNazivDataGridViewColumn.HeaderText = "Naziv";
			this.uxNazivDataGridViewColumn.Name = "uxNazivDataGridViewColumn";
			this.uxNazivDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxNazivDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxNazivDataGridViewColumn.ReadOnly = false;		
			//
			// uxIDRoditeljDataGridViewColumn
			//
			this.uxIDRoditeljDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIDRoditeljDataGridViewColumn.DataPropertyName = "IDRoditelj";
			this.uxIDRoditeljDataGridViewColumn.HeaderText = "IDRoditelj";
			this.uxIDRoditeljDataGridViewColumn.Name = "uxIDRoditeljDataGridViewColumn";
			this.uxIDRoditeljDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIDRoditeljDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIDRoditeljDataGridViewColumn.ReadOnly = false;		
			//
			// uxHierarchyDataGridViewColumn
			//
			this.uxHierarchyDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxHierarchyDataGridViewColumn.DataPropertyName = "Hierarchy";
			this.uxHierarchyDataGridViewColumn.HeaderText = "Hierarchy";
			this.uxHierarchyDataGridViewColumn.Name = "uxHierarchyDataGridViewColumn";
			this.uxHierarchyDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxHierarchyDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxHierarchyDataGridViewColumn.ReadOnly = false;		
			//
			// uxLvlDataGridViewColumn
			//
			this.uxLvlDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxLvlDataGridViewColumn.DataPropertyName = "Lvl";
			this.uxLvlDataGridViewColumn.HeaderText = "Lvl";
			this.uxLvlDataGridViewColumn.Name = "uxLvlDataGridViewColumn";
			this.uxLvlDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxLvlDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxLvlDataGridViewColumn.ReadOnly = true;		
			//
			// uxAbstraktnaDataGridViewColumn
			//
			this.uxAbstraktnaDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxAbstraktnaDataGridViewColumn.DataPropertyName = "Abstraktna";
			this.uxAbstraktnaDataGridViewColumn.HeaderText = "Abstraktna";
			this.uxAbstraktnaDataGridViewColumn.Name = "uxAbstraktnaDataGridViewColumn";
			this.uxAbstraktnaDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxAbstraktnaDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxAbstraktnaDataGridViewColumn.ReadOnly = false;		
			
			// this
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.Controls.Add(this.uxArtiklKategorijaDataGridView);
			this.Name = "ArtiklKategorijaDataGridView";
			this.Size = new System.Drawing.Size(470, 300);
			((System.ComponentModel.ISupportInitialize)(this.uxArtiklKategorijaErrorProvider)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxArtiklKategorijaDataGridView)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxArtiklKategorijaBindingSource)).EndInit();
			this.ResumeLayout(false);
		}
		#endregion
				
		#region events
		
		/// <summary>
		/// Raised the CurrentEntityChanged event.
		/// </summary>
		protected void OnCurrentEntityChanged()
		{
			if (CurrentEntityChanged != null)
			{
				ArtiklKategorijaDataGridViewEventArgs args = new ArtiklKategorijaDataGridViewEventArgs();
				args.ArtiklKategorija = _currentArtiklKategorija;
				CurrentEntityChanged(this, args); 
			}
		}
		
		#endregion
		
		/// <summary>
		/// Strongly typed event 
		/// </summary>
		public class ArtiklKategorijaDataGridViewEventArgs : System.EventArgs
		{
			private Entities.ArtiklKategorija	_ArtiklKategorija;
	
			/// <summary>
			/// the  Entities.ArtiklKategorija instance.
			/// </summary>
			public Entities.ArtiklKategorija ArtiklKategorija
			{
				get { return _ArtiklKategorija; }
				set { _ArtiklKategorija = value; }
			}	
		}
		
		/// <summary>
		/// Handles the DataError event of the uxArtiklKategorijaDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewDataErrorEventArgs"/> instance containing the event data.</param>
		protected void OnArtiklKategorijaDataGridViewDataError(object sender, System.Windows.Forms.DataGridViewDataErrorEventArgs e)
		{
			System.Diagnostics.Debug.WriteLine(string.Format( "{0}, {1}", e.ColumnIndex, e.RowIndex));
		}
		
		/// <summary>
		/// Handles the CellValueNeeded event of the uxArtiklKategorijaDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnArtiklKategorijaDataGridViewCellValueNeeded(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxArtiklKategorijaDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIDDataGridViewColumn":
						e.Value = ArtiklKategorijaList[e.RowIndex].ID;
						break;
					case "uxNazivDataGridViewColumn":
						e.Value = ArtiklKategorijaList[e.RowIndex].Naziv;
						break;
					case "uxIDRoditeljDataGridViewColumn":
						e.Value = ArtiklKategorijaList[e.RowIndex].IDRoditelj;
						break;
					case "uxHierarchyDataGridViewColumn":
						e.Value = ArtiklKategorijaList[e.RowIndex].Hierarchy;
						break;
					case "uxLvlDataGridViewColumn":
						e.Value = ArtiklKategorijaList[e.RowIndex].Lvl;
						break;
					case "uxAbstraktnaDataGridViewColumn":
						e.Value = ArtiklKategorijaList[e.RowIndex].Abstraktna;
						break;
				default:
				break;
			}
		}
		
		/// <summary>
		/// Handles the CellValuePushed event of the uxArtiklKategorijaDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnArtiklKategorijaDataGridViewCellValuePushed(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxArtiklKategorijaDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIDDataGridViewColumn":
						ArtiklKategorijaList[e.RowIndex].ID = (System.Int32)e.Value;
						break;
					case "uxNazivDataGridViewColumn":
						ArtiklKategorijaList[e.RowIndex].Naziv = (System.String)e.Value;
						break;
					case "uxIDRoditeljDataGridViewColumn":
						ArtiklKategorijaList[e.RowIndex].IDRoditelj = (System.Int32?)e.Value;
						break;
					case "uxHierarchyDataGridViewColumn":
						ArtiklKategorijaList[e.RowIndex].Hierarchy = (System.String)e.Value;
						break;
					case "uxLvlDataGridViewColumn":
						ArtiklKategorijaList[e.RowIndex].Lvl = (System.Int32?)e.Value;
						break;
					case "uxAbstraktnaDataGridViewColumn":
						ArtiklKategorijaList[e.RowIndex].Abstraktna = (System.Boolean)e.Value;
						break;
				default:
				break;
			}
		}
	}
}
